<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>日程管理-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<link type="text/css" rel="stylesheet" href="__PUBLIC__/css/fullcalendar.css" />
<style>
	#calendar{ width: 100%;}
	#modal-delete.opacity{ opacity: 1; z-index: 1052; background: rgba(0,0,0,0.5); }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">个人 > 日程管理</div>
	</div>
	<div id="content" class="clearboth">
		<div class="classify">
			<ul>
				<li><a href="javascript:;" class="current">日程管理日历</a></li>
				<li><a href="__APP__/Index/schedule_other">日程管理列表</a></li>
			</ul>
		</div>
		<div class="index_title">
			日程
		</div>
		<div id="calendar"></div>
	</div>
</div>
<!-- 弹框 -->
<div class="modal fade" id="date_modal">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<div class="modal-header">
				<h4>日程</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<div class="form-main" style="border:none;margin-bottom:0">
					<div class="date_show dayClick_s" style="border-bottom:1px solid #e5e5e5;">
						<div class="form-item clearfix">
							<div class="input-label"><span class="asterisk">*</span>选择日期</div>
							<div class="input-item">
								<input type="text" name="date" class="form-control Wdate w100 required-text dayClick_s" <literal>onclick="WdatePicker({minDate:'%y-%M-{%d-7}',maxDate:'%y-%M-{%d+7}'})"</literal> readonly autocomplete="off"/>
								<span class="txt hide mr10 dayClick_h"></span>
								<span class="error-item">必填项</span>
							</div>
						</div>
					</div>
					<div class="hide date_hide dayClick_h" style="border-bottom:1px solid #e5e5e5;">
						<div class="form-item clearfix">
							<div class="input-label"><span class="asterisk">*</span>开始日期</div>
							<div class="input-item">
								<input type="text" name="start_date" class="form-control Wdate w100 required-text dayClick_s" id="d4321" <literal>onclick="WdatePicker({minDate:'%y-%M-{%d-7}',maxDate:'#F{$dp.$D(\'d4322\')||\'%y-%M-{%d+7}\'}'})"</literal> readonly autocomplete="off"/>
								<span class="txt hide mr10 dayClick_h"></span>
								<span class="error-item">必填项</span>
							</div>
						</div>
						<div class="form-item clearfix">
							<div class="input-label"><span class="asterisk">*</span>结束日期</div>
							<div class="input-item">
								<input type="text" name="end_date" class="form-control Wdate w100 required-text dayClick_s" id="d4322" <literal>onclick="WdatePicker({minDate:'#F{$dp.$D(\'d4321\')||\'%y-%M-{%d-7}\'}',maxDate:'%y-%M-{%d+7}'})"</literal> readonly autocomplete="off"/>
								<span class="txt hide mr10 dayClick_h"></span>
								<span class="error-item">必填项</span>
							</div>
						</div>
					</div>
					<div class="form-item clearfix btn_hide dayClick_s" style="border:none;">
						<div class="input-label"><label class="checkbox-inline left more_date" style="line-height:30px"><input type="checkbox" value="">选择多天</label></div>
						<div class="input-item">
							<button type="button" class="btn next_show dayClick_s">下一步</button><button type="button" class="btn next_hide hide dayClick_h">下一步</button><span class="error-item ml10 more-item">您选择的日期填报类型已满</span>
						</div>
					</div>
					<div class="hide tb_hide dayClick_h" style="border-bottom:1px solid #e5e5e5;">
						<div class="form-item clearfix">
							<div class="input-label"><span class="asterisk">*</span>填报类型</div>
							<div class="input-item schedule_btn"></div>
						</div>
						<div class="form-item clearfix">
							<div class="input-label"><span class="asterisk">*</span>项目</div>
							<div class="input-item">
								<select name="pid" class="form-control select-add w300" autocomplete="off">
									<option value="-10" t-name="">请选择</option>
								</select>
								<span class="error-item">必填项</span>
							</div>
						</div>
						<div class="form-item clearfix">
							<div class="input-label"><span class="asterisk">*</span>填报岗位</div>
							<div class="input-item">
								<select name="fill_post" class="form-control select-add w150" autocomplete="off">
									<option value="-10" t-name="">请选择</option>
								</select>
								<span class="error-item">必填项</span>
							</div>
						</div>
						<div class="load_box"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 弹框 -->
<div class="modal fade" id="edit_modal">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<div class="modal-header">
				<h4>编辑日程</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<div class="form-main" style="border:none;margin-bottom:0">
					<div class="form-item clearfix">
						<div class="input-label">日期</div>
						<div class="input-item">
							<span class="txt mr10 ajax_date"></span>
						</div>
					</div>
					<div class="form-item clearfix">
						<div class="input-label">填报类型</div>
						<div class="input-item">
							<span class="txt mr10 ajax_lx"></span>
						</div>
					</div>
					<div class="form-item clearfix">
						<div class="input-label">项目</div>
						<div class="input-item">
							<select name="pid_edit" class="form-control select-add w300" autocomplete="off">
								<option value="-10" t-name="">请选择</option>
							</select>
							<span class="txt mr10"></span>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="form-item clearfix">
						<div class="input-label">填报岗位</div>
						<div class="input-item">
							<select name="fill_edit" class="form-control select-add w150" autocomplete="off">
								<option value="-10" t-name="">请选择</option>
							</select>
							<span class="txt mr10"></span>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="load_box"></div>
				</div>
			</div>
		</div>
	</div>
</div>
<!--删除弹框-->
<div class="modal fade" id="modal-delete" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>确认提示框</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">您确定要删除吗？</div>
			<div class="modal-footer">
				<button type="button" class="btn delete-confirm">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<!--重新提交框-->
<div class="modal fade" id="myModal_submit">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>重新提交</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<table class="table table-bordered">
					<tr>
						<td class="text-right"><strong><span class="asterisk">*</span>原因</strong></td>
						<td>
							<textarea name="remark" placeholder="重新提交理由" class="form-control w300 submit_info left" autocomplete="off"></textarea>
							<span class="error-item left">必填项</span>
						</td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-affirm">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript" src="__PUBLIC__/js/moment.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/fullcalendar.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/zh-cn.js"></script>
<script type="text/javascript">
$(function(){
	$('.btn-default,.fa-times').click(function(){
		$('#modal-delete').fadeOut();
	})
	$('.delete-confirm').click(function(){
		var zid = $(this).attr('zid');
		$('#modal-delete,#edit_modal').hide();
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"id":zid,"action":"delete"},
			url:"__APP__/Index/schedule_list_action",
			success:function(data){
				success_pop(data.status,data.msg);
			}
		})
	})
	//下一步
	$('.next_show').click(function(){
		if($("[name='date']").val()==''){
			$("[name='date']").nextAll('.error-item').show();
		}else{
			$("[name='start_date']").val('');
			$("[name='end_date']").val('');
			var dates = $("[name='date']").val();
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"date":dates,"action":"type"},
				url:"__APP__/Index/schedule_list_ajax",
				success:function(data){
					if(data['has_type']==1){
						$('.next_show').parents('.form-item').hide();
						$('.tb_hide').show();
						$("[name='date']").hide().next('.txt').show().html(dates);
						if(data['way']==2){
							$('.load_box').load("__APP__/Index/schedule_list_add/way/1");
						}else{
							$('.load_box').load("__APP__/Index/schedule_list_add/way/"+data['way']+"");
						}
						var html='';
						for(var i=0;i<data['type'].length;i++){
							html+="<a ";
							if(data['type'][i].name1==data['way']){
								html+="class='active "+data['type'][i].name3+"'";
							}else{
								html+="class='"+data['type'][i].name3+"'";
							}
							html+="href='javascript:void(0)' type='"+data['type'][i].name1+"'>"+data['type'][i].name2+"</a>";
							if(i!=data['type'].length-1){
								html+="<span>|</span>";
							}
						}
						$('.schedule_btn').html(html);
						var phtml="<option value='-10'>请选择</option>";
						for(var i=0;i<data['plist'].length;i++){
							phtml+="<option value='"+data['plist'][i].id+"'>["+data['plist'][i].project_num+"]"+data['plist'][i].project_name+"</option>";
						}
						$("[name='pid']").html(phtml).select2();
						var fhtml="<option value='-10'>请选择</option>";
						for(var t=0;t<data['fill_post'].length;t++){
							fhtml+="<option value='"+data['fill_post'][t].name1+"'>"+data['fill_post'][t].name2+"</option>";
						}
						$("[name='fill_post']").html(fhtml).select2();
					}else{
						$('.next_show').nextAll('.error-item').show();
					}
				}
			})
		}
	})
	$('.next_hide').click(function(){
		var tag = true;
		if($("[name='start_date']").val()==''){
			$("[name='start_date']").nextAll('.error-item').show();
			tag = false;
		}
		if($("[name='end_date']").val()==''){
			$("[name='end_date']").nextAll('.error-item').show();
			tag = false;
		}
		if(tag){
			$("[name='date']").val('');
			var start = $("[name='start_date']").val(),
				end = $("[name='end_date']").val();
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"start":start,"end":end,"action":"type"},
				url:"__APP__/Index/schedule_list_ajax",
				success:function(data){
					if(data['has_type']==1){
						$('.next_hide').parents('.form-item').hide();
						$('.tb_hide').show();
						$("[name='start_date']").hide().next('.txt').show().html(start);
						$("[name='end_date']").hide().next('.txt').show().html(end);
						if(data['way']==2){
							$('.load_box').load("__APP__/Index/schedule_list_add/way/1");
						}else{
							$('.load_box').load("__APP__/Index/schedule_list_add/way/"+data['way']+"");
						}
						var html='';
						for(var i=0;i<data['type'].length;i++){
							html+="<a ";
							if(data['type'][i].name1==data['way']){
								html+="class='active "+data['type'][i].name3+"'";
							}else{
								html+="class='"+data['type'][i].name3+"'";
							}
							html+="href='javascript:void(0)' type='"+data['type'][i].name1+"'>"+data['type'][i].name2+"</a>";
							if(i!=data['type'].length-1){
								html+="<span>|</span>";
							}
						}
						$('.schedule_btn').html(html);
						var phtml="<option value='-10'>请选择</option>";
						for(var i=0;i<data['plist'].length;i++){
							phtml+="<option value='"+data['plist'][i].id+"'>["+data['plist'][i].project_num+"]"+data['plist'][i].project_name+"</option>";
						}
						$("[name='pid']").html(phtml).select2();
						var fhtml="<option value='-10'>请选择</option>";
						for(var t=0;t<data['fill_post'].length;t++){
							fhtml+="<option value='"+data['fill_post'][t].name1+"'>"+data['fill_post'][t].name2+"</option>";
						}
						$("[name='fill_post']").html(fhtml).select2();
					}else{
						$('.next_show').nextAll('.error-item').show();
					}
				}
			})
		}
	})
	//开始结束日期
	$('.more_date input').click(function(){
		if($(this).prop("checked")){
			// $("[name='start_date']").val('');
			// $("[name='end_date']").val('');
			$('.date_show,.next_show').hide();
			$('.date_hide,.next_hide').show();
		}else{
			// $("[name='date']").val('');
			$('.date_show,.next_show').show();
			$('.date_hide,.next_hide').hide();
		}
	})
	//填报load
	$('body').on('click','.tb_zg',function(){
		$('.load_box').load("__APP__/Index/schedule_list_add/way/1");
	})
	$('body').on('click','.tb_cc',function(){
		$('.load_box').load("__APP__/Index/schedule_list_add/way/1");
	})
	$('body').on('click','.tb_xx',function(){
		$('.load_box').load("__APP__/Index/schedule_list_add/way/3");
	})
	$('body').on('click','.tb_qj',function(){
		$('.load_box').load("__APP__/Index/schedule_list_add/way/4");
	})
	$('body').on('click','.schedule_btn a',function(){
		$(this).addClass('active').siblings().removeClass('active');
		$("[name='pid'],[name='fill_post']").val('-10').select2();
		$("[name='pid']").nextAll('.error-item').hide();
		$("[name='fill_post']").nextAll('.error-item').hide();
	})
	//隐藏提示
	$('.required-text').focus(function(){
		$(this).nextAll('.error-item').hide();
	})
	$('.select-add').change(function(){
		$(this).nextAll('.error-item').hide();
	})
	$("[name='date']").click(function(){
		$('.more-item').hide();
	})
	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth();
	var y = date.getFullYear();
	$('#calendar').fullCalendar({
		header: {
			left: 'prevYear prev,today,next nextYear',
			center: 'title',
			right: '',
		},
		lang: 'zh-cn',
		contentHeight:500,
		defaultView: 'month',
		validRange: function(currentDate) { 
			return { 
				start: currentDate.clone().subtract(1, 'year'), 
				end: currentDate.clone().add(3, 'year') // exclusive end, so 3 
			}; 
		},
		events: 'json.php',
		dayClick: function(date, jsEvent, view){
			var date = date.format();
			$('#date_modal').modal("show");
			$('#date_modal .schedule_btn a').attr('mid',date);
			$('.dayClick_s').show();
			$('.dayClick_h,.more-item').hide();
			$(".more_date input").removeAttr("checked");
			$('#date_modal .required-text').val('');
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"date":date,"action":"dates"},
				url:"__APP__/Index/schedule_list_ajax",
				success:function(data){
					if(data['nodate']==1){
						//超过7天
						
					}else{
						//7天内
						//data['date'] 点击的日期
						$("[name='date'],[name='start_date']").val(data['date']);

					}
				}
			})
		},
		eventClick: function(calEvent, jsEvent, view) {
			$('#edit_modal').modal("show");
			var id = calEvent.id;
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"id":id,"action":"type"},
				url:"__APP__/Index/schedule_list_edit",
				success:function(data){
					$('.ajax_date').html(data['detail']['show_date']);
					$('.ajax_lx').html(data['detail']['type_name']);
					if(data['detail']['noedit']==1||data['detail']['status']>=1){
						$("[name='pid_edit']").next('.select2').remove();
						$("[name='fill_edit']").next('.select2').remove();
						$("[name='pid_edit']").hide().nextAll('.txt').show().html(data['detail']['project']);
						$("[name='fill_edit']").hide().nextAll('.txt').show().html(data['detail']['fill_post_name']);
					}else{
						var phtml="<option value='-10'>请选择</option>";
						for(var i=0;i<data['plist'].length;i++){
							phtml+="<option value='"+data['plist'][i].id+"'";
							if(data['plist'][i].id==data['detail'].pid){
								phtml+=" selected";
							}
							phtml+=">["+data['plist'][i].project_num+"]"+data['plist'][i].project_name+"</option>";
						}
						$("[name='pid_edit']").html(phtml).select2();
						var thtml="<option value='-10'>请选择</option>";
						for(var t=0;t<data['fill_post'].length;t++){
							thtml+="<option value='"+data['fill_post'][t].name1+"'";
							if(data['fill_post'][t].name1==data['detail'].fill_post){
								thtml+=" selected";
							}
							thtml+=">"+data['fill_post'][t].name2+"</option>";
						}
						$("[name='fill_edit']").html(thtml).select2();
						$("[name='pid_edit']").nextAll('.txt').html('').hide();
						$("[name='fill_edit']").nextAll('.txt').html('').hide();
					}
					if((data['detail']['type']==1)||(data['detail']['type']==2)){
						$('#edit_modal .load_box').load("__APP__/Index/schedule_list_add/way/1/id/"+data['detail']['id']);
					}else if(data['detail']['type']==3){
						$('#edit_modal .load_box').load("__APP__/Index/schedule_list_add/way/3/id/"+data['detail']['id']);
					}else if(data['detail']['type']==4){
						$('#edit_modal .load_box').load("__APP__/Index/schedule_list_add/way/4/id/"+data['detail']['id']);
					}

				}
			});
		},
		events: function(start,end,timezone, callback) {
        	var date = this.getDate().format('YYYY-MM');
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"date":date,"action":"detail"},
				url:"__APP__/Index/schedule_list_ajax",
				success:function(data){
					var events = [];
					if(data){
						$.each(data,function(i,c) {
							events.push({
								id: c.id,
								title: ''+c.project_name+'',
								start: c.start_date,
								end: c.end_date,
								backgroundColor: ''+c.color+''
							});
						});
					}else{
						events: [
						]
					}
					callback(events);
				}
			})
		}
	}); 

});
</script>
</body>
</html>
